package com.dkm.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "permission")
public class Permission {

	@Id
	private String permission_id;
	private String permission_value;
	private String permission_module;
	private String permission_name;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date update_time;
	
	//权限和角色多对多关系
	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(
			name = "role_permission",
			joinColumns = {@JoinColumn(name="permission_id")},
			inverseJoinColumns = {@JoinColumn(name="role_id")}
	)
	private List<Role> roles;
	
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	public Permission() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Permission(String permission_id, String permission_value, String permission_module, String permission_name,
			Date update_time) {
		super();
		this.permission_id = permission_id;
		this.permission_value = permission_value;
		this.permission_module = permission_module;
		this.permission_name = permission_name;
		this.update_time = update_time;
	}
	public String getPermission_id() {
		return permission_id;
	}
	public void setPermission_id(String permission_id) {
		this.permission_id = permission_id;
	}
	public String getPermission_value() {
		return permission_value;
	}
	public void setPermission_value(String permission_value) {
		this.permission_value = permission_value;
	}
	public String getPermission_module() {
		return permission_module;
	}
	public void setPermission_module(String permission_module) {
		this.permission_module = permission_module;
	}
	public String getPermission_name() {
		return permission_name;
	}
	public void setPermission_name(String permission_name) {
		this.permission_name = permission_name;
	}
	public Date getUpdate_time() {
		return update_time;
	}
	public void setUpdate_time(Date update_time) {
		this.update_time = update_time;
	}
	@Override
	public String toString() {
		return "Permission [permission_id=" + permission_id + ", permission_value=" + permission_value
				+ ", permission_module=" + permission_module + ", permission_name=" + permission_name + ", update_time="
				+ update_time + "]";
	}
	
}
